package com.ruoyi.car.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.car.pojo.TPartBatteryPackInformation;
import com.car.pojo.TPartBatteryPackModel;
import com.car.pojo.TPartBatteryPackModelValue;
import com.car.pojo.TPartPatternAssembly;
import com.ruoyi.car.mapper.TPartBatteryPackInformationMapper;
import com.ruoyi.car.mapper.TPartBatteryPackModelMapper;
import com.ruoyi.car.mapper.TPartBatteryPackModelValueMapper;
import com.ruoyi.car.service.BatteryPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional
@Service
public class BatteryPackageServiceimpl implements BatteryPackageService {
    @Autowired
    private TPartBatteryPackModelMapper tPartBatteryPackModelMapper;
    @Autowired
    private TPartBatteryPackInformationMapper tPartBatteryPackInformationMapper;
    @Autowired
    private TPartBatteryPackModelValueMapper tPartBatteryPackModelValueMapper;

    //优化时可用json方式调用模组包含参数
    public List<TPartBatteryPackInformation> findAllTPartBatteryPackInformation(Map map){
        List<TPartBatteryPackInformation> tPartBatteryPackInformations = tPartBatteryPackInformationMapper.selectList(null);
        List<TPartBatteryPackInformation> list = tPartBatteryPackInformationMapper.selectByMap(map);
        return list;
    }
    @Override
    public List<TPartBatteryPackModel> findAllTPartBatteryPackModel(TPartBatteryPackModel tPartBatteryPackModel) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("bag_model_name",tPartBatteryPackModel.getBagModelName());
        List<TPartBatteryPackModel> tPartBatteryPackModels = tPartBatteryPackModelMapper.selectList(queryWrapper);
        return tPartBatteryPackModels;
    }


    @Override
    public int addInformation(TPartBatteryPackInformation tPartBatteryPackInformation) {
        tPartBatteryPackInformation.setBatteryBagId(IdWorker.getId()+"");
        //int insert = tPartBatteryPackInformationMapper.insert(tPartBatteryPackInformation);
        return tPartBatteryPackInformationMapper.insert(tPartBatteryPackInformation);
    }
    @Override
    public int addTPartBatteryPackModel(TPartBatteryPackModel tPartBatteryPackModel) {
        return 0;
    }


    @Override
    public TPartBatteryPackInformation selectTPartBatteryPackInformationById(String tPartBatteryPackId) {
        return tPartBatteryPackInformationMapper.selectById(tPartBatteryPackId);
    }
    @Override
    public TPartBatteryPackModel selectTPartBatteryPackModelById(String tPartBatteryPackModelId) {
        return tPartBatteryPackModelMapper.selectById(tPartBatteryPackModelId);
    }



    @Override
    public int updateTPartBatteryPackInformation(TPartBatteryPackInformation tPartBatteryPackInformation) {
        return tPartBatteryPackInformationMapper.updateById(tPartBatteryPackInformation);
    }
    @Override
    public int updateTPartBatteryPackModelId(TPartBatteryPackModel tPartBatteryPackModel) {
        return 0;
    }


    @Override
    public int deleteTPartBatteryPackInformationByIds(String ids) {
        String[] split = ids.split(",");
        for (String s:split){
            tPartBatteryPackInformationMapper.deleteById(s);
        }
        return 1;
    }

    @Override
    public List<TPartBatteryPackModelValue> findAllGroupInterfaceOfPackage(String id) {
        QueryWrapper<TPartBatteryPackModelValue> queryWrapper = new QueryWrapper<TPartBatteryPackModelValue>();
        queryWrapper.eq("battery_pack_model_id",id);
        List<TPartBatteryPackModelValue> tPartBatteryPackModelValues = tPartBatteryPackModelValueMapper.selectList(queryWrapper);
        return tPartBatteryPackModelValues;
    }

    @Override
    public int deleteTPartBatteryPackModelByIds(String Modelids) {
        String[] split = Modelids.split(",");
        QueryWrapper<TPartBatteryPackModelValue> queryWrapper = new QueryWrapper<>();
        for (String s:split){
            queryWrapper.eq("battery_pack_model_id",s);
            tPartBatteryPackModelMapper.deleteById(s);
            tPartBatteryPackModelValueMapper.delete(queryWrapper);
        }
        return 1;
    }



}
